#ifndef __ALGO_ASR_DTW_H__
#define __ALGO_ASR_DTW_H__

//#include "pbdata.h"
#include <string.h>
#include "stdint.h"
#include <stdbool.h>
#include "app_timer.h"
#include "spi_flash.h"

//#define MELREADADD        (uint32_t*)(0x0007C000)
#define MELREADADD          0x0007C000
#define MELREF0ADD          0x00078000
#define MELREF1ADD          0x00074000
#define MELREF2ADD          0x00070000
#define MELREF3ADD          0x0006C000
#define MELREF4ADD          0x00068000
#define MELREF5ADD          0x00064000
#define MELREF6ADD          0x00060000
#define MELREF7ADD          0x0005C000
#define MELREF8ADD          0x00058000
#define MELREF9ADD          0x00054000

#define MELREADADDPOINT   (uint32_t*)(MELREADADD)
#define MELREF0ADDPOINT   (uint32_t*)(MELREF0ADD)
#define MELREF1ADDPOINT   (uint32_t*)(MELREF1ADD)
#define MELREF2ADDPOINT   (uint32_t*)(MELREF2ADD)
#define MELREF3ADDPOINT   (uint32_t*)(MELREF3ADD)
#define MELREF4ADDPOINT   (uint32_t*)(MELREF4ADD)
#define MELREF5ADDPOINT   (uint32_t*)(MELREF5ADD)
#define MELREF6ADDPOINT   (uint32_t*)(MELREF6ADD)
#define MELREF7ADDPOINT   (uint32_t*)(MELREF7ADD)
#define MELREF8ADDPOINT   (uint32_t*)(MELREF8ADD)
#define MELREF9ADDPOINT   (uint32_t*)(MELREF9ADD)

typedef enum
{
    flash_mel_read      = 2,                    // 存储用户等识别语音mel系数
    flash_mel_ref1      = 3,                    // 参考语音1 mel 系数
    flash_mel_ref2      = 4,                    // 参考语音2 mel 系数
    flash_mel_ref3      = 5,                    // 参考语音3 mel 系数
    flash_mel_ref4      = 6,                    // 参考语音4 mel 系数
    flash_mel_ref5      = 7,                    // 参考语音5 mel 系数
    flash_mel_ref6      = 8,                    // 参考语音6 mel 系数
    flash_mel_ref7      = 9,                    // 参考语音7 mel 系数
    flash_mel_ref8      = 10,                    // 参考语音8 mel 系数
    flash_mel_ref9      = 11,                    // 参考语音9 mel 系数
    flash_mel_ref10     = 12,                   // 参考语音10 mel 系数
}flash_write_sector;

typedef struct
{
    flash_write_sector flash_write;             // 定义mel系数要写的sector
    uint8_t len[11];                            // 定义mel系数的长度
}Audio_Mel_Cep;


////extern uint8_t audio_point;

////extern Audio_Mel_Cep m_mel_cep;

typedef struct{
    short len;
    //¶¨ÒåÖ¸ÏòconstµÄÖ¸Õë,(Ö¸ÕëÖ¸ÏòµÄÄÚÈÝ²»ÄÜ±»ÐÞ¸Ä)
    const float (*mfcc)[24];
}MelMfccCep;

typedef enum
{
    mel_read,
    mel_ref0,
    mel_ref1,
    mel_ref2,
    mel_ref3,
    mel_ref4,
    mel_ref5,
    mel_ref6,
    mel_ref7,
    mel_ref8,
    mel_ref9
}Melcep_all;

typedef struct
{
    uint32_t* melcep_add;             // melcep 的存储地址
    uint32_t melcep_len;              // melcep 的长度
}alg_asr_melcep;

extern const float MelRef0[][24];
extern const float MelRef1[][24];
extern const float MelRef2[][24];
extern const float MelRef3[][24];
extern const float MelRef4[][24];
extern const float MelRef5[][24];
extern const float MelRef6[][24];
extern const float MelRef7[][24];
extern const float MelRef8[][24];
extern const float MelRef9[][24];


uint8_t Melcep(int16_t * buf_add,int16_t start_point,int16_t end_point,float* mel_buf);
void Meldtw(alg_asr_melcep * mel_cep,float *distence,uint8_t cnt);
float dtw(uint32_t* audio_add,uint32_t audio_len,uint32_t* lib_add,uint32_t lib_len);
float VectorSum(float *v,short l);
void algo_dtw_set_audio_point(uint8_t point);
//extern int16_t fram_pcm_data[256];

extern volatile bool flash_read_flag;
extern bool mel_cep_over_flag;

////extern uint8_t my_buff[16];

////extern uint32_t * Base_Add;

#endif // __ALGO_ASR_DTW_H__
